package com.jinke.api.modules.ums.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jinke.api.modules.ums.mapper.CancelApiLogMapper;
import com.jinke.api.modules.ums.mapper.PreSucLogMapper;
import com.jinke.api.modules.ums.model.PreSucLog;
import com.jinke.api.modules.ums.service.ICancelApiLogService;
import com.jinke.api.modules.ums.service.IPreSucLogService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 预报成功表
 */
@Service
public class PreSucLogServiceImpl extends ServiceImpl<PreSucLogMapper, PreSucLog> implements IPreSucLogService {



    /**
     * 未执行的数据保存取消订单日志
     *
     * @param channelId
     * @param userId
     * @param requestId
     * @param orderId
     * @param orderNumber 第三方的
     */
    @Override
    public void saveLog(Integer channelId, Integer userId, String requestId, Integer orderId, String orderNumber) {
        Thread thread = new Thread(() -> {

            PreSucLog log = new PreSucLog();
            log.setChannelId(channelId);
            log.setUserId(userId);
            log.setRequestId(requestId);
            log.setOrderId(orderId);
            log.setOrderNumber(orderNumber);
            save(log);
        });
        thread.start();
    }

    /**
     * 更新日志
     *
     * @param
     */
    @Override
    public void updateCancelApiLog(PreSucLog log) {
        Thread thread = new Thread(() -> {
            updateById(log);
        });
        thread.start();
    }

    /**
     * 获取不超过6次预报成功转正式成功的
     *
     * @return
     */
    @Override
    public List<PreSucLog> getList() {


        LambdaQueryWrapper<PreSucLog> queryWrapper = new LambdaQueryWrapper<PreSucLog>()
                .eq(PreSucLog::getIsSucesss, 0)
                .lt(PreSucLog::getTryTime, 6);
        List<PreSucLog> log = list(queryWrapper);


        return log;
    }


}
